<template>
  <vs-sidebar click-not-close position-right parent="body" default-index="1" color="primary" class="add-new-data-sidebar items-no-padding" spacer v-model="isSidebarActiveLocal">
    <div class="mt-6 flex items-center justify-between px-6">
        <h4>{{ Object.entries(this.data).length === 0 ? "添加" : "编辑" }}</h4>
        <feather-icon icon="XIcon" @click.stop="isSidebarActiveLocal = false,activity={},imgFile=null" class="cursor-pointer"></feather-icon>
    </div>
    <vs-divider class="mb-0"></vs-divider>

    <component :is="scrollbarTag" class="scroll-area--data-list-add-new" :settings="settings" :key="$vs.rtl">

    
       
      <div class="p-6">

        <vs-select label="处理方式" v-model="activity.type" class="mt-5 w-full">
          <vs-select-item key="" value="" text="请选择类型" disabled checked/>
          <vs-select-item
            v-for="(item,index) in typeOption"
            :key="index"
            :value="item.value"
            :text="item.name" />
        </vs-select>

  

      </div>
    </component>

    <div class="flex flex-wrap items-center p-6" slot="footer">
      <vs-button class="mr-6" @click="submitData" :disabled="!isFormValid">提交</vs-button>
      <vs-button type="border" color="danger" @click="isSidebarActiveLocal = false,activity={}">取消</vs-button>
    </div>
  </vs-sidebar>
</template>

<script>
import VuePerfectScrollbar from 'vue-perfect-scrollbar'

export default {
  props: {
    isSidebarActive: {
      type: Boolean,
      required: true
    },
    data: {
      type: Object,
      default: () => {}
    }
  },
  components: {
    VuePerfectScrollbar
  },
  data () {
    return {
      player_skins_id: 115786,
        player_id: 651,
        itemId: 115786,
     
      activity:{
        id:'',
        player_id:'',
        itemId:''
        
      },
     
      typeOption:[
        {"name":'发货',"value":"1"},
        {"name":'回退',"value":"2"},
      ]
    }
  },
  watch: {
    isSidebarActive (val) {
      if (!val){
        this.initValues()
        return
      }
      // console.log(this.data);
      if (Object.entries(this.data).length === 0) {
        this.initValues()
        this.$validator.reset()
      } else {
        const { id, player_id,itemId} = JSON.parse(JSON.stringify(this.data))
        this.activity.id = id;
        this.activity.player_id = player_id;
        this.activity.itemId = itemId;
        
      }
    },
    // "activity.start_time":{
    //   handler(val){
    //     console.log(val);
    //   }
    // },
  },
  computed: {
    isSidebarActiveLocal: {
      get () {
        return this.isSidebarActive
      },
      set (val) {
        if (!val) {
          this.$emit('closeSidebar')
          // this.$validator.reset()
          // this.initValues()
        }
      }
    },
    isFormValid () {
      // return !this.errors.any() && this.dataName && this.dataCategory && this.dataPrice > 0
      return true
    },
    scrollbarTag () { return this.$store.getters.scrollbarTag }
  },
  methods: {
    initValues () {
      // if (this.data.id) return
      this.activity = {
      
        type:''
      };
    
    },
    submitData () {
      // this.$validator.validateAll().then(result => {
      //   if (result) {
        let _this = this;
        let params = {
        player_skins_id: _this.player_skins_id,
        player_id: _this.player_id,
        itemId: _this.itemId,
      }
        
        let url =  "/index/User/skinToSteanew";
        _this.$axios({
          url: url,
          method: "post",
          data: params,
          
        }).then((res) => {
          console.log(res);
          if(res.data.status == 1){
            _this.$vs.notify({
              title: '提示',
              text: res.data.msg,
              iconPack: 'feather',
              icon: 'icon-alert-circle',
              color: 'success'
            })
            this.$emit('closeSidebar');
            this.$emit('get');
            // this.initValues();
          }else{
            _this.$vs.notify({
              title: '提示',
              text: res.data.msg,
              iconPack: 'feather',
              icon: 'icon-alert-circle',
              color: 'danger'
            })
          }
        });
          return

          this.$emit('closeSidebar')
          this.initValues()
      //   }
      // })
    },
    Delete(text,index){
      if(text == 'data'){
        this.dataImgs.splice(index,1);
      }else if(text == 'base'){
        this.baseImgs.splice(index,1);
        this.imgFiles.splice(index,1);
      }
    },
    updateCurrImg (input) {
      if (input.target.files && input.target.files[0]) {
        const reader = new FileReader()
        reader.onload = e => {
          this.dataImg = e.target.result;
          this.baseImgs.push(e.target.result)
          // this.activity.img = e.target.result;
          this.imgFile = input.target.files[0];
          this.imgFiles.push(input.target.files[0])
        }
        reader.readAsDataURL(input.target.files[0])
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.add-new-data-sidebar {
  ::v-deep .vs-sidebar--background {
    z-index: 52010;
  }

  ::v-deep .vs-sidebar {
    z-index: 52010;
    width: 400px;
    max-width: 90vw;

    .img-upload {
      margin-top: 2rem;

      .con-img-upload {
        padding: 0;
      }

      .con-input-upload {
        width: 100%;
        margin: 0;
      }
    }
  }
}

.scroll-area--data-list-add-new {
    // height: calc(var(--vh, 1vh) * 100 - 4.3rem);
    height: calc(var(--vh, 1vh) * 100 - 16px - 45px - 82px);

    &:not(.ps) {
      overflow-y: auto;
    }
}
.upload-img{
  padding-left: 20px;
}
.delete{
  margin-left: 5px;
  visibility: hidden;
}

.img-1-1{
  padding-right: 10px;
  &:hover{
    .delete{
      visibility:visible;
    }
  }
}
.responsive{
  width: 100%;
  max-height: 100px;
  object-fit: contain;
}
</style>
